﻿using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.StyleElements
{
    [XmlRoot("numFmts", Namespace = Constants.ExcelMain)]
    public class NumberFormats : XmlSerializable
    {
        [Optional]
        [XmlAttribute("count", Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> Count { get; set; }

        [Optional]
        [XmlElement("numFmt", Namespace = Constants.ExcelMain)]
        public XmlList<NumberFormat> Formats { get; set; }

        public NumberFormats() 
        {
            Formats = new XmlList<NumberFormat>();
        }

        public void AddNumberFormat(uint formatId, string formatCode)
        {
            if (Count == null)
            {
                Count = 0;
            }

            NumberFormat nf = new NumberFormat()
            {
                Id = formatId,
                Code = formatCode,
            };
            Formats.Add(nf);
            Count++;
        }
    }
}
